package cn.com.bluemoon.daps.system.vo;

import cn.com.bluemoon.daps.system.entity.DapSystemBizLineDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author Jarod.Kong
 */
@Data
public class BizLineDetailRequestVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("系统id")
    @NotEmpty(message = "系统id不可为空")
    private String systemId;

    @ApiModelProperty(value = "管理员，存工号")
    @Size(max = 100, message = "最大选择{max}个")
    private List<String> admins;

    @ApiModelProperty(value = "开发人员，存工号")
    @Size(max = 200, message = "最大选择{max}个")
    private List<String> develops;

    public BizLineDetailRequestVo() {
    }

    public BizLineDetailRequestVo(DapSystemBizLineDetail detail) {
        BeanUtils.copyProperties(detail, this);
    }

    public DapSystemBizLineDetail toModel() {
        DapSystemBizLineDetail model = new DapSystemBizLineDetail();
        model.setBizLineId(null);
        model.setSystemId(systemId);
        if (admins !=null) {
            model.setAdmins(String.join(",", admins));
        }
        if (develops !=null) {
            model.setDevelops(String.join(",", develops));
        }
        return model;
    }
}
